﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.DAL;
using AnyOffice.Components;

namespace AnyOffice.Web.general.system.netshareMager
{
    public partial class index : BasePage
    {
        string mangerid = "";
        string mangertid = "";
        private readonly DiskDao bll = new DiskDao();
        private readonly DiskTypeDao dbll = new DiskTypeDao();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(! IsPostBack)
            {
                if (!IsManger())
                { 
                 Response.Write("没有可管理的公共文档柜！");
                 Response.End();
                }
            }
        }

        /// <summary>
        /// 权限判断
        /// </summary>
        /// <returns></returns>
        public bool IsManger() {
            bool istrue = false;
            List<Model.DiskType> disktype = dbll.GetModelList(base.Conn, " DiskTypeName <> '" + Public_fold.DiskTypeName2 + "'");
            foreach (Model.DiskType dt in disktype)
            {
                List<AnyOffice.Model.Disk> disk = bll.GetListByparentId(base.Conn, " ParentDiskID=0 and DiskTypeID=" + dt.DiskTypeID + " order by Seq asc");
                foreach (Model.Disk d in disk)
                {
                    if (Public_fold.IsCanDel(base.User.Identity.Name, d.DiskID.ToString())) //判定是否有管理权限
                    {
                        mangerid += d.DiskID + ",";
                        string typeid = "," + dt.DiskTypeID + ",";
                        if (mangertid.IndexOf(typeid) == -1)
                        {
                            mangertid += "," + dt.DiskTypeID + ",";
                        }
                        istrue = true;
                    }
                    else { continue; }
                }

            }
           Session["mangerid"] = mangerid;
           Session["mangertid"] = mangertid;
            return istrue;
        }
    }
}